package com.climber.spb_rabbitmq.spb_lazy.controller;

import com.climber.spb_rabbitmq.spb_lazy.config.RabbitMQConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MessageController {

    @Autowired
    RabbitTemplate rabbitTemplate;

    /**
     * 发布消息
     * 以队列为单位设置消息的延时
     *
     * @param content
     */
    @GetMapping("/sendLazyMessage/{content}")
    public void sendLazyMessage(@PathVariable("content") String content) {
        for (int i = 1; i < 6; i++) {
            rabbitTemplate.convertAndSend(RabbitMQConfig.X_EXCHANGE, RabbitMQConfig.ROUTING_KEY_L, content+i);
        }
    }

}